#!/usr/bin/python3
import sys
import math

try:
    t = int(input())
    if t < 1 or t > 50:
        sys.exit(0)
    for x in range(t):
        inputStr = input()
        if inputStr != "":
            p = int(inputStr)
            if p < 0 or p > math.pow(10, 60):
                sys.exit(0)
            if p < 2333:
                print("Case #%d: %d" % (x + 1, 2333))
            elif p < 12333:
                print("Case #%d: %d" % (x + 1, 12333))
            else:
                if '2333' in inputStr:
                    maxN = 10000
                else:
                    maxN = 9999
                for n in range(maxN):
                    p += 1
                    if '2333' in str(p):
                        break
                print("Case #%d: %d" % (x + 1, p))
        else:
            break
except ValueError:
    pass
except EOFError:
    pass
except MemoryError:
    pass
